<?php

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;


/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var yiike\store\merchant\models\OrderStoreSearch $searchModel
 */

$this->title = Yii::t('models', 'Order Stores');
$this->params['breadcrumbs'][] = $this->title;

if (isset($actionColumnTemplates)) {
    $actionColumnTemplate = implode(' ', $actionColumnTemplates);
    $actionColumnTemplateString = $actionColumnTemplate;
} else {
    Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . 'New', ['create'], ['class' => 'btn btn-success']);
    $actionColumnTemplateString = "{view} {update} {delete}";
}
$actionColumnTemplateString = '<div class="action-buttons">'.$actionColumnTemplateString.'</div>';
?>
<style>
    .grouped-row {
        height: 40px;
        line-height: 40px;
        vertical-align: middle;
        font-weight: bold;
        background: #efefef;
    }
</style>
<?php
echo $this->render('_search', ['model' =>$searchModel]);
?>
<div class="box box-info giiant-crud order-store-index">
    <div class="box-body">

        <?php
        echo \kartik\export\ExportMenu::widget([
                'dataProvider' => $dataProvider,
                'columns' => [
                    'orderStore.trade_id',
                    'order.name',
                    'order.mobile',
                    'order.province',
                    'order.city',
                    'order.district',
                    'order.address',
                    'goods_sn',
                    'title',
                    'spec',
                    'num'
                ],
                'fontAwesome' => true,
                'batchSize' => 10,
                'target' => '_blank',
                //'folder' => '@webroot/tmp', // this is default save folder on server
            ])
        ?>

        <?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function(){alert("yo")}']]) ?>

        <div class="">
            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'pager' => [
                    'class' => yii\widgets\LinkPager::className(),
                    'firstPageLabel' => 'First',
                    'lastPageLabel' => 'Last',
                ],
                'striped' => false,
//                'filterModel' => $searchModel,
//                'responsive' => false,
                'responsiveWrap' => false,
                'tableOptions' => ['class' => 'table'],
                'headerRowOptions' => ['class'=>'x'],
                'columns' => [
                    [
                        'attribute'=>'orderStore.trade_id',
//                        'width'=>'310px',
                        'content'=>function ($model) {
                            return '订单号: '.$model->orderStore->trade_id. '&nbsp;&nbsp;&nbsp;&nbsp;合计: '.$model->orderStore->settlement;
                        },
                        'group'=>true,
                        'groupedRow'=>true,
                        'groupOddCssClass'=>'grouped-row',
                        'groupEvenCssClass'=>'grouped-row',
                        'groupFooter'=>function ($model) {
                            return [
                                'mergeColumns'=>[[0, 11]], // columns to merge in summary

                            ];
                        }
                    ],
                    [
                        'width'=>'130px',
//                        'filter' => false,
                        'content'=>function ($model) {
                            $html = '<i class="hidden">'.$model->order_id.'</i>';
                            if ($model->orderStore->status == 1) {
//                                $html .= Html::a('发货', Url::to(['view', 'id' => $model->orderStore->id]), ['class' => 'btn btn-warning btn-sm']);
                            }
                            $html .= Html::a('<i class="fa fa-files-o"></i> 详情', Url::to(['view', 'id' => $model->orderStore->id]), ['class' => 'btn btn-warning  btn-sm']);
                            return $html;
                        },
                        'group'=>true,
                        'subGroupOf'=> 1,
                        'groupOddCssClass'=>'',
                        'groupEvenCssClass'=>'',
                    ],
                    [
                        'header' => '状态',
                        'width'=>'120px',
//                        'filter' => false,
                        'content'=>function ($model) {
                            $status_option = $model->orderStore->status_option;
                            return $status_option[$model->order->type][$model->orderStore->status];
                        },
                        'group' => true,
                        'subGroupOf' => 0,
                        'groupOddCssClass'=>'',
                        'groupEvenCssClass'=>'',
                    ],
                    [
                        'attribute' => 'logo',
                        'filter' => false,
                        'width'=>'70px',
                        'content' => function ($model) {
                            return Html::img($model->logo, ['style' => 'max-width:70px;max-height:50px;']);
                        }
                    ],
                    [
                        'attribute' => 'goods_sn',
                        'width' => '150px',
                    ],
                    'title',
                    [
                        'attribute' => 'spec',
                    ],
                    [
                        'attribute' => 'cost_price',
                    ],
                    [
                        'attribute' => 'num',
                    ],
                    'order.created_at:datetime',
                    'orderStore.pay_at:datetime',
                    'orderStore.express_at:datetime',
                    [

                    ]
                ],
            ]); ?>
        </div>
        <?php \yii\widgets\Pjax::end() ?>
    </div>
</div>




